package com.example.sofa_module;

import android.util.Log;

import com.example.common.field.DataActionEntity;
import com.example.common.mvvm.model.BaseRespository;
import com.example.common.mvvm.viewmodel.BaseViewModel;
import com.example.network_sdk.BaseEntity;
import com.example.sofa_module.entity.TagDataXEntity;
import com.example.sofa_module.entity.TagEntity;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class SofaViewModel extends BaseViewModel<SofaRespository> {

    @Override
    public void onResult(BaseEntity entity) {
        if (entity instanceof TagEntity){
            TagEntity tagEntity= (TagEntity) entity;
            Log.i("dataTagSize", "onResult: "+tagEntity.data.data.size());
            DataActionEntity dataActionEntity=new DataActionEntity();
            Map<String,Object> map=new HashMap<>();
            map.put("data",tagEntity.data.data);
            dataActionEntity.data=map;
            dataActionEntity.action="sofa";
            getUiDataFunction().getUiData().postValue(dataActionEntity);
        }
    }

    @Override
    public void initData() {
        respository.getSofaData(0,10,0,"all",1)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(this);
    }
}
